Skip to content

feat: expose parent Agent tool IDs in subagent callbacks - #1573

Open
austinchennn wants to merge 1 commit into
anthropics:mainfrom
austinchennn:codex/issue-1469-parent-tool-hook-context
Open

austinchennn wants to merge 1 commit into
anthropics:mainfrom
austinchennn:codex/issue-1469-parent-tool-hook-context

Conversation

@austinchennn

Copy link
Copy Markdown

What was wrong

Tool-lifecycle hooks and ToolPermissionContext expose agent_id for subagent calls but not the parent Agent call's tool_use_id. A host cannot group the subagent's tool cards under the spawning call at hook time. Current Claude Code control requests do not include that parent ID, although the CLI writes it as toolUseId in the subagent metadata sidecar already used by get_subagent_messages().

The change

  • Add optional parent_tool_use_id to the four tool-lifecycle hook input types, SubagentStart/Stop hook inputs, and ToolPermissionContext. Keep the new dataclass field last for positional compatibility.
  • Prefer a direct control-protocol field when a future CLI sends it. For current local CLI sessions, resolve the parent ID from the same sidecar source used by session reads, using the hook transcript path or the initialized session ID/CWD. Cache successful lookups; missing or unreadable metadata leaves the field absent/None without failing a callback.
  • Cover direct-wire permission input, sidecar fallback for permission callbacks (including nested workflow metadata), and all six requested hook kinds.

This addresses the SDK side of #1469. It does not change Claude Code's control payloads; sessions without a local sidecar still need CLI support to provide the ID. I am deliberately using Refs #1469 rather than auto-closing the issue until that limitation is reviewed.

Testing

  • On unmodified main with the new targeted tests: 18 failures.
  • uv run --extra dev pytest tests/ -q: 1773 passed, 6 skipped.
  • uv run --extra dev ruff check src/ tests/ scripts/, ruff format --check, mypy src/ scripts/, and git diff --check: passed.
  • Not run: live CLI subagent/model integration, virtual SessionStore backend, or remote session storage. The installed CLI 2.1.287 does not yet include the field in can_use_tool requests.

Implementation and tests were assisted by OpenAI Codex; I reviewed the code and local checks.

@austinchennn

Copy link
Copy Markdown
Author

The workflows for current head 02b58a9e2e168ab4b31ce6ccfee0b30a52335792 — Lint, Test, and Security check for workflows that call Claude — currently show action_required, so they have not run successfully yet. Could a maintainer approve the pending workflows and review whether the SDK-side metadata fallback is an appropriate scope? The PR records the local checks and the remaining live-CLI/nonlocal-session limitations; it uses Refs #1469 so those unresolved cases are not auto-closed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant